﻿// -----------------------------------------------------------------------
// <copyright file="ConnectionStringBuilders.cs" company="JSC Centido">
//  Copyright (c) JSC Centido. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace Centido.Core
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    ///   A connection string builder container.
    /// </summary>
    public static class ConnectionStringBuilders
    {
        /// <summary>
        ///   Connection string builders
        /// </summary>
        private static readonly ICollection<ConnectionStringBuilder> Builders
            = new List<ConnectionStringBuilder>
                {
                    new OracleConnectionStringBuilder(),
                    new SqlServerConnectionStringBuilder()
                };


        /// <summary>
        ///   Get connection string builder
        /// </summary>
        /// <param name = "dbProviderName">Db provider name</param>
        /// <returns>Connection string builder or null</returns>
        public static ConnectionStringBuilder GetBuilder(string dbProviderName)
        {
            if (dbProviderName == null)
                throw new ArgumentNullException("dbProviderName");
            if (dbProviderName.Trim().Length == 0)
                throw new ArgumentException("Database provider name cannot be empty.");

            dbProviderName = dbProviderName.Trim().ToUpper();

            var builder = Builders.FirstOrDefault(b => b.DbProviderName.ToUpper() == dbProviderName);

            return builder != null ? builder.CreateNew() : null;
        }
    }
}